package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.CshBank;
import com.bestow.basic.service.ICshBankService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 银行定义Controller
 * 
 * @author liliu
 * @date 2022-09-26
 */
@RestController
@RequestMapping("/basic/bank")
public class CshBankController extends BaseController
{
    @Autowired
    private ICshBankService cshBankService;

    /**
     * 查询银行定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(CshBank cshBank)
    {
        startPage();
        List<CshBank> list = cshBankService.selectCshBankList(cshBank);
        return getDataTable(list);
    }

    /**
     * 导出银行定义列表
     */
    @PreAuthorize("@ss.hasPermi('basic:bank:export')")
    @Log(title = "银行定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CshBank cshBank)
    {
        List<CshBank> list = cshBankService.selectCshBankList(cshBank);
        ExcelUtil<CshBank> util = new ExcelUtil<CshBank>(CshBank.class);
        util.exportExcel(response, list, "银行定义数据");
    }

    /**
     * 获取银行定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:bank:query')")
    @GetMapping(value = "/{bankId}")
    public AjaxResult getInfo(@PathVariable("bankId") Long bankId)
    {
        return AjaxResult.success(cshBankService.selectCshBankByBankId(bankId));
    }

    /**
     * 新增银行定义
     */
    @PreAuthorize("@ss.hasPermi('basic:bank:add')")
    @Log(title = "银行定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CshBank cshBank)
    {
        return toAjax(cshBankService.insertCshBank(cshBank));
    }

    /**
     * 修改银行定义
     */
    @PreAuthorize("@ss.hasPermi('basic:bank:edit')")
    @Log(title = "银行定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CshBank cshBank)
    {
        return toAjax(cshBankService.updateCshBank(cshBank));
    }

    /**
     * 删除银行定义
     */
    @PreAuthorize("@ss.hasPermi('basic:bank:remove')")
    @Log(title = "银行定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankIds}")
    public AjaxResult remove(@PathVariable Long[] bankIds)
    {
        return toAjax(cshBankService.deleteCshBankByBankIds(bankIds));
    }
}
